{{ header }}{{ column_left }}
<div id="content">
  <div class="page-header">
    <div class="container-fluid">
      <button type="button" data-bs-toggle="tooltip" title="{{ button_filter }}" onclick="$('#filter-manufacturer').toggleClass('d-none');" class="btn btn-light d-md-none d-lg-none"><i class="fa-solid fa-filter"></i></button>
      <div class="float-end">
        <a href="{{ add }}" data-bs-toggle="tooltip" title="{{ button_add }}" class="btn btn-primary"><i class="fa-solid fa-plus"></i></a>
        <div class="btn-group">
          <button type="button" class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown"><i class="fa-solid fa-list-check"></i> {{ button_action }} <i class="fa-solid fa-caret-down fa-fw"></i></button>
          <ul class="dropdown-menu">
            <li><button type="submit" form="form-manufacturer" formaction="{{ enable }}" class="dropdown-item"><i class="fa-solid fa-toggle-on text-success"></i> {{ text_enable }}</button></li>
            <li><button type="submit" form="form-manufacturer" formaction="{{ disable }}" class="dropdown-item"><i class="fa-solid fa-toggle-off text-danger"></i> {{ text_disable }}</button></li>
            <li>
              <hr class="dropdown-divider">
            </li>
            <li><button type="submit" form="form-manufacturer" formaction="{{ delete }}" onclick="return confirm('{{ text_confirm }}');" class="dropdown-item"><i class="fa-regular fa-trash-can text-danger"></i> {{ text_delete }}</button></li>
          </ul>
        </div>
      </div>
      <h1>{{ heading_title }}</h1>
      <ol class="breadcrumb">
        {% for breadcrumb in breadcrumbs %}
          <li class="breadcrumb-item"><a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a></li>
        {% endfor %}
      </ol>
    </div>
  </div>
  <div class="container-fluid">
    <div class="row">
      <div id="filter-manufacturer" class="col-lg-3 col-md-12 order-lg-last d-none d-lg-block mb-3">
        <div class="card filter-sticky">
          <div class="card-header"><i class="fa-solid fa-filter"></i> {{ text_filter }}</div>
          <div class="card-body">
            <form id="form-filter">
              <div class="mb-3">
                <label class="form-label">{{ entry_name }}</label>
                <input type="text" name="filter_name" value="{{ filter_name }}" placeholder="{{ entry_name }}" id="input-name" data-oc-target="autocomplete-name" class="form-control" autocomplete="off"/>
                <ul id="autocomplete-name" class="dropdown-menu"></ul>
              </div>
              <div class="mb-3">
                <label for="input-store-id" class="form-label">{{ entry_store }}</label>
                <select name="filter_store_id" id="input-store-id" class="form-select">
                  <option value=""></option>
                  {% for store in stores %}
                    <option value="{{ store.store_id }}"{% if store.store_id == filter_store_id %} selected{% endif %}>{{ store.name }}</option>
                  {% endfor %}
                </select>
              </div>
              <div class="mb-3">
                <label for="input-language" class="form-label">{{ entry_language }}</label>
                <select name="filter_language_id" id="input-store" class="form-select">
                  <option value=""></option>
                  {% for language in languages %}
                    <option value="{{ language.language_id }}"{% if language.language_id == filter_language_id %} selected{% endif %}>{{ language.name }}</option>
                  {% endfor %}
                </select>
              </div>
              <div class="mb-3">
                <label for="input-status" class="form-label">{{ entry_status }}</label> <select name="filter_status" id="input-status" class="form-select">
                  <option value=""></option>
                  <option value="1"{% if filter_status == '1' %} selected{% endif %}>{{ text_enabled }}</option>
                  <option value="0"{% if filter_status == '0' %} selected{% endif %}>{{ text_disabled }}</option>
                </select>
              </div>
              <div class="text-end">
                <button type="submit" id="button-filter" class="btn btn-light"><i class="fa-solid fa-filter"></i> {{ button_filter }}</button>
                <button type="reset" data-bs-toggle="tooltip" title="{{ button_reset }}" class="btn btn-outline-secondary"><i class="fa-solid fa-filter-circle-xmark"></i></button>
              </div>
            </form>
          </div>
        </div>
      </div>
      <div class="col-lg-9 col-md-12">
        <div class="card">
          <div class="card-header"><i class="fa-solid fa-list"></i> {{ text_list }}</div>
          <div id="list" class="card-body">{{ list }}</div>
        </div>
      </div>
    </div>
  </div>
</div>
<script type="text/javascript"><!--
$('#form-filter').on('submit', function(e) {
    e.preventDefault();

    let url = $(this).serialize();

    window.history.pushState({}, null, 'index.php?route=catalog/manufacturer&user_token={{ user_token }}&' + url);

    $('#list').load('index.php?route=catalog/manufacturer.list&user_token={{ user_token }}&' + url);
});

$('#input-name').autocomplete({
    'source': function(request, response) {
        $.ajax({
            url: 'index.php?route=catalog/manufacturer.autocomplete&user_token={{ user_token }}&filter_name=' + encodeURIComponent(request),
            dataType: 'json',
            success: function(json) {
                response($.map(json, function(item) {
                    return {
                        label: item['name'],
                        value: item['manufacturer_id']
                    }
                }));
            }
        });
    },
    'select': function(item) {
        $('#input-name').val(item['label']);
    }
});
//--></script>
{{ footer }}
